package com.xyht.medicine_management_system.modules.consumptionPoint.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.CommonResult;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.consumptionPoint.entity.req.MmsConsumptionPointRuleReq;
import com.xyht.medicine_management_system.modules.consumptionPoint.service.MmsConsumptionPointRuleService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;

/**
 * <p>
 * 积分规则表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-06
 */
@RestController
@SecretBody
@RequestMapping("/pointRule")
public class MmsConsumptionPointRuleController {
    @Resource
    private MmsConsumptionPointRuleService mmsConsumptionPointRuleService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加积分规则")
    @PostMapping("/add")
    public ResponseResult addConsumptionPointRule(@RequestBody MmsConsumptionPointRuleReq ruleReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsConsumptionPointRuleService.addConsumptionPointRule(ruleReq, userId);
    }

    @ApiModelProperty("删除积分规则")
    @PostMapping("/del")
    public ResponseResult delConsumptionPointRule(@RequestParam("ruleId") String[] ruleId) {
        mmsConsumptionPointRuleService.removeByIds(Arrays.asList(ruleId));
        return CommonResult.success();
    }

    @ApiModelProperty("修改积分规则")
    @PostMapping("/update")
    public ResponseResult updateConsumptionPointRule(@RequestBody MmsConsumptionPointRuleReq ruleReq) {
        return mmsConsumptionPointRuleService.updateConsumptionPointRule(ruleReq);
    }

    @ApiModelProperty("积分规则列表")
    @GetMapping("/list")
    public ResponseResult listConsumptionPointRule(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "startDate", required = false) Date startDate,
                                                   @RequestParam(value = "endDate", required = false) Date endDate,
                                                   @RequestParam(value = "status", required = false) Integer status,
                                                   @RequestParam(value = "searchStr", required = false) String searchStr) {
        return mmsConsumptionPointRuleService.listConsumptionPointRule(pageNum, pageSize, startDate, endDate, status, searchStr);
    }

    @ApiModelProperty("积分规则详情")
    @GetMapping("/detail")
    public ResponseResult ruleDetail(@RequestParam("ruleId") String ruleId) {
        return mmsConsumptionPointRuleService.ruleDetail(ruleId);
    }
}

